﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 考核八
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        bool a = false;
        public class Dbx
        {
            public List<Point> lp;
            public Dbx()
            {
                lp = new List<Point>();
            }
        }
        List<Dbx> ld = new List<Dbx>();
        Dbx tempd = new Dbx();

        private void Form2_MouseDown(object sender, MouseEventArgs e)
        {
            if(e.Button==MouseButtons.Left)
            {
                Point pt = new Point();
                pt.X = e.X;
                pt.Y = e.Y;
                tempd.lp.Add(pt);
                //ld.Add(tempd);
                //Invalidate();
            }
            if (e.Button == MouseButtons.Right)
            {
                ld.Add(tempd);
                Invalidate();
                tempd = new Dbx();
                a = true;
            }
        }

        private void Form2_Paint(object sender, PaintEventArgs e)
        {
            //if (a == true)
            //{
                Graphics g = e.Graphics;
                Pen pen = new Pen(Color.Red, 2);
                foreach (Dbx d in ld)
                {
                    Point[] p = d.lp.ToArray();
                    g.DrawPolygon(pen, p);

                }
            //}
        }
    }
}
